/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.HttpConnection;

import global.*;

/**
 *
 * @author lenovo
 */
public class ProcessServerResponse {
    /*--------------------------------------------------
    * Process a response from a server
    -------------------------------------------------*/
    public static boolean ServerResponse(HttpConnection http, InputStream iStrm) throws IOException
    {
        boolean bRes = false;
        if (http.getResponseCode() == HttpConnection.HTTP_OK)
        {
              int length = (int) http.getLength();
              if (length != -1)
              {
                    byte servletData[] = new byte[length];
                    iStrm.read(servletData);
                    Global.sServerRespon = new String(servletData);
              }
              else
              {
                    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();
                    int ch;
                    while ((ch = iStrm.read()) != -1)
                      bStrm.write(ch);
                    Global.sServerRespon = new String(bStrm.toByteArray());
                    bStrm.close();
                    System.out.print("Server: " + Global.sServerRespon);
              }
              bRes = true;
        }
        return  bRes;
    }
}
